#!/usr/bin/python3``
# -*- coding: utf-8 -*-``
# @Author : SZ2316108 欧阳亨杰``
import ddt
import pandas as pd
import unittest
import requests


file_valid = pd.read_csv('../data/valid_login_data.csv')
df_valid = pd.DataFrame(file_valid)
data_valid = df_valid.to_dict(orient='records')

file_invalid = pd.read_csv('../data/invalid_login_data.csv')
df_invalid = pd.DataFrame(file_invalid)
data_invalid = df_invalid.to_dict(orient='records')


@ddt.ddt
class test_valid_Login_interface(unittest.TestCase):
    base_url = 'http://127.0.0.1:8081/user/login'

    @classmethod
    def setUpClass(cls) -> None:
        print("-----开始执行test_valid_Login_interface-----")

    @ddt.data(*data_valid)
    def test_login_valid(self, data):
        response = requests.post(self.base_url, data=data)
        data = response.json()

        print(data)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(data['code'], 0) # 表示正确登录

    @ddt.data(*data_invalid)
    def test_login_invalid(self, data):
        response = requests.post(self.base_url, data=data)
        data = response.json()

        print(data)
        self.assertEqual(response.status_code, 200) # 表示请求成功
        self.assertEqual(data['code'], 500)  # 表示错误登录
        self.assertEqual(data['msg'], '账号或密码错误')  # 表示错误登录

    @classmethod
    def tearDownClass(cls) -> None:
        print("-----test_valid_Login_interface结束-----")


if __name__ == '__main__':
    unittest.main()
